#include <SGE.h>
using namespace SGE;

#include "FrontendState.h"
#include "PlayState.h"

//base class pointer relies on polymorphism to call proper load, unload etc.
GameState* currentState = nullptr;
NextState nextState = Frontend;
GameContext gameContext;

void SGE_Initialize()
{
}

void SGE_Terminate()
{
}

bool SGE_Update(float deltaTime) 
{
	//If there is no state
	if(nextState != None)
	{
		//Unload current state
		if(currentState != nullptr)
		{
			currentState -> Unload();
			delete currentState;
		}

		//Change state
		switch(nextState)
		{
			case Frontend:
				currentState = new FrontendState(gameContext);
				break;
			case Gameplay:
				currentState = new PlayState(gameContext);
				break;
		}
		//Load new current state;
		currentState -> Load();
	}

	nextState = currentState -> Update(deltaTime);

	//currentState -> Update(deltaTime);

	if(nextState == Quit) 
	{
		currentState -> Unload();
		delete currentState;
		return true;
	}
	return false;
}

void SGE_Render()
{
	currentState -> Render();
}